#pragma once
#include <iostream>
#include <string>
#include <list>
#include <set>

class Command
{
public:
    Command()
    {
        _safe_cmd.insert("ls -l");
        _safe_cmd.insert("pwd");
        _safe_cmd.insert("whoami");

    }
    std::string Execute(std::string& cmdstr)
    {
        // if(_safe_cmd.find(cmdstr) == _safe_cmd.end())return "Unsafe Command";
        FILE* fp = popen(cmdstr.c_str(),"r");

        if(fp ==nullptr)return std::string();

        std::string result;
        char buffer[1024];
        while(fgets(buffer,sizeof buffer,fp))
        {
            result += buffer;
        }


        pclose(fp);
        return result;
    }



private:
    std::set<std::string> _safe_cmd;
};


